package com.lsp.controller;


import com.lsp.service.MallServeice;
import com.lsp.service.SkuInfoService;
import com.lsp.vo.SearchParam;
import com.lsp.vo.SearchResult;
import com.shop.pojo.pms.Pms_Sku_Info;
import com.shop.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@RestController
@RequestMapping("/search")
public class SearchController {

    @Autowired
    SkuInfoService skuInfoService;
@Autowired
    MallServeice mallServeice;
//自动将页面提交过来的所有请求查询参数封装成指定的对象
    //搜索页面的es搜索
    @GetMapping("/SearchParam")
    public Object listPage(SearchParam searchParam)  {

        return  mallServeice.search(searchParam);
    }
    //查询sku表里的随机三条数据
    @GetMapping("/listSkuByCatalogId")
    public List<Pms_Sku_Info> SelectListBySku(Integer catalog_id){

        return skuInfoService.SelectListBySku(catalog_id);
    }
    //商品上架到es
    @PostMapping("/addSpu/{spuId}")
    public R addSku(@PathVariable("spuId") Long spuId){

        return mallServeice.skuPutaway(spuId);
    }
//商品从es下架
    @DeleteMapping("/delSpu/{spuId}")
    public R delSku(@PathVariable("spuId") Long spuId){

        return mallServeice.skuSoldOut(spuId);
    }

}
